package com.gery.tn.ui;

import java.awt.Color;
import java.awt.Cursor;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;



public class StatusBar extends JPanel {

    private JLabel status;
    private JButton hyperlinkButton;
    private ImageIcon img;
    private ImageIcon hyperlinkNormal;
    
    
    public StatusBar() {
        this.setBounds(0, 500, 679, 30);
        this.setLayout(null);
        img = new ImageIcon(this.getClass().getClassLoader().getResource("com/gery/tn/ui/images/statusBarImage.png"));
        hyperlinkNormal = new ImageIcon(this.getClass().getClassLoader().getResource("com/gery/tn/ui/images/hyperlinkImage.png"));
        
        status = new JLabel(" Welcome Cynthia! :)");
        status.setFont(new Font("Apple", Font.BOLD, 11));
        status.setForeground(new Color(230, 230, 230));
        status.setBounds(10, 1, 400, 20);
        
        hyperlinkButton = new JButton();
        hyperlinkButton.setBounds(550, 2, 108, 20);
        hyperlinkButton.setIcon(hyperlinkNormal);
        hyperlinkButton.setBorder(null);
        
        this.add(status);
        this.add(hyperlinkButton);
        
        
        //--- Event handling
        hyperlinkButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    java.awt.Desktop.getDesktop().browse(new URI("http://tianails.com"));
                } catch (IOException | URISyntaxException ex) {
                    Logger.getLogger(StatusBar.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
        hyperlinkButton.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseEntered(MouseEvent e) {
                hyperlinkButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
            }
        });
    }
            
    
    @Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);      
        g.drawImage(img.getImage(), 0, 0, this.getWidth(), this.getHeight(), this);
    }
    
    public void setStatus(String stat) {
        status.setText(stat);
    }
    
}
